<!DOCTYPE html>
<html lang="en">
<style>
    body {
        background-image:url("../bootstrap/imgs/3.jpg");
        background-size: cover;

    }
    #form-login {
        display: flex;
        height: 100vh;
        justify-content: center;
        align-items: center;
    }
</style>
<head>
    <meta charset="UTF-8">
    <title>登录系统</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<!--    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" >-->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.css" >
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="/bootstrap/js/jquery-3.3.1.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="/bootstrap/js/bootstrap.min.js"></script>
<!--    &lt;!&ndash; 可选的 Bootstrap 主题文件（一般不用引入） &ndash;&gt;-->
<!--    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">-->
</head>
<form  id="form-login"class="text-center">
    <div style="width: 500px">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h1>欢 迎 登 录</h1>
            </div>
            <label class="sr-only" >用户名</label>
            <input type="text" id="username" name="username" class="form-control" placeholder="Username" >

            <label class="sr-only" >密码</label>
            <input type="password"id="password" name="password" class="form-control" placeholder="Password" >

        <!--    <label class="sr-only" >类型</label>
            <input type="text"id="type" name="type" class="form-control"  placeholder="Type">-->
            <select id="type" name="type"class="selectpicker show-tick form-control" title="Type">
                <option  hidden>Type</option>
                　　<option value="0">医生</option>
                　　　　<option value="1">挂号管理员</option>
                <option value="2">药房管理员</option>
            </select>
                　　　　

    <button class="btn btn-lg btn-primary btn-block" type="button" id="btn-login">登录</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    $("#btn-login").click(function() {

        $.ajax({
            "url":"/users/login",
            "data":{
                username:$('input[name="username"]').val(),
                password:$('input[name="password"]').val(),
                type:$("#type option:selected").val(),
            },
            "type":"get",
            "dataType":"json",
            "success":function (data) {
                console.log(data);
                      if (data.state == 2000) {
                        if ($("#type option:selected").val()== 0)
                        {
                            alert("欢迎医生");

                            location.href = "/tohome";
                        }
                        if ($("#type option:selected").val() == 1)
                        {
                            alert("欢迎挂号管理员");
                            location.href = "/register/selectRegister.html";
                        }
                        if ($("#type option:selected").val() == 2)
                        {
                            alert("欢迎药房管理员");
                            location.href = "/start/html";
                        }
                    } else {
                        alert("登录失败：" + data.message);
                    }
                }
        });
    });
</script>
</body>
</html>
